using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation;

namespace MicroSnake
{
    class ListBoxTextMenuItem : ListBoxItem
    {
        private Text content;

        public ListBoxTextMenuItem(Text content) : base()
        {
            this.content = content;
            this.Child = content;
            this.Background = null;            
        }

        public override string ToString()
        {
            return content.TextContent;
        }

        public override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);
        }

        protected override void OnIsSelectedChanged(bool isSelected)
        {
            if (isSelected)
            {
                this.Background = new SolidColorBrush(MicroSnakeColors.MenuItemSelectedBackgroundColor);
                content.ForeColor = MicroSnakeColors.MenuItemSelectedForeColor;
            }
            else
            {
                this.Background = null;  // Trasparent
                content.ForeColor = MicroSnakeColors.MenuItemForeColor;
            }
        }

        /// <summary>
        /// Built a list box menu item with a specific content
        /// </summary>
        /// <param name="stringResource"></param>
        /// <returns></returns>
        public static ListBoxTextMenuItem Make(Resources.StringResources stringResource)
        {
            Text txtItem = new Text();
            txtItem.Font = Resources.GetFont(Resources.FontResources.small);
            txtItem.ForeColor = MicroSnakeColors.MenuItemForeColor;
            txtItem.HorizontalAlignment = HorizontalAlignment.Center;
            txtItem.TextAlignment = TextAlignment.Center;
            txtItem.VerticalAlignment = VerticalAlignment.Center;
            txtItem.SetMargin(6);

            txtItem.TextContent = Resources.GetString(stringResource);

            return new ListBoxTextMenuItem(txtItem);
        }
    }
}
